<?php
include_once "DBCORE.cls.php";
	/**
	*  
	*/
	class db_Catedishes
	{
		private $tablename="tblcatedishes";
		private $db;
		function __construct()
		{
			$this->db=new DBCORE();
			$this->db->db_connect("localhost", "root", "", "restaurant");
			$this->db->db_query("SET NAMES 'UTF8'");
		}
		public function select($id)
		{
			if(empty($id))
				return false;
			$myStrSQL ="SELECT * FROM {$this->tablename} WHERE CateDishesID ='{$id}'";
			$data = $this->db->db_fetch_assoc($this->db->db_query($myStrSQL));
			return $data;
		}		
		public function selectAll($id = '')
		{
			if(empty($id))
				return false;
			$myStrSQL = "SELECT * FROM {$this->tablename} WHERE 1";
			$result = $this->db->db_query($myStrSQL);
			$resArray = array();
			while($row = $this->db->db_fetch_assoc($result))
			{
				$resArray[] = $row;
			}
			return $resArray;
		}
		public function delete($id)
		{
			$id = !Empty($id) ? "WHERE CateDishesID = {$id}":"";
			$myStrSQL = "DELETE FROM {$this->tablename} {$id}";
			return $this->db->db_query($myStrSQL);
		}
		public function deleteAll()
		{
			$myStrSQL = "DELETE FROM {$this->tablename} WHERE 1" ;
			return $this->db->db_query($myStrSQL);
		}
		public function insert(array $data)
		{
			$id = $data['Id'];
			$DishesName = $data['DishesName'];
			$rootPath = $data['rootPath'];
			$webPath = $data['webPath'];
			$myStrSQL = "INSERT INTO {$this->tablename} VALUES('$id', '$DishesName', '$rootPath', 'webPath')";
			return $this->db->db_query($myStrSQL);
		}
		public function inserts($data)
		{
			foreach($data as $key => $value)
			{
				if($this->checkExists($value['Id']))
					return false;
				insert($value);
			} 
		}
		public function update($update = array(), $condition)
		{
			if(empty($condition))
				return;
			$update = "DishesName = '{$update['DishesName']}', rootPath='{$update['rootPath']}', webPath='{$update['webPath']}'";
			$condition = "CateDishesID = '{$condition}'";
			$myStrSQL = "UPDATE {$this->tablename} SET {$update} WHERE {$condition}";
			return $this->db->db_query($myStrSQL);
		}
		public function findbyCondition(array $data)
		{
			$myStrSQL = "SELECT * FROM {$this->tablename} WHERE 1";
			if(!empty($data['Id']))
				$myStrSQL = $myStrSQL." AND CateDishesID='".$data['Id']."'";
			if(!empty($data['Fullname']))
				$myStrSQL = $myStrSQL." AND DishesName='".$data['DishesName']."'";			
			$result=$this->db->db_query($myStrSQL);
			$resArray = array();
			while ($row = $this->db->db_fetch_assoc($result)) {
				$resArray[] = $row;
			}
			return $resArray;
		}
		//
		
		public function checkExists($id='')
		{
			if(empty($id))
				return false;
			$myStrSQL = "SELECT * FROM {$this->tablename} WHERE CateDishesID ='{$id}'";
			return $this->db->db_query($myStrSQL);
			
		}
	}
?>